﻿<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="UTF-8" />
<link href="../../../style.css" rel="stylesheet" type="text/css" />
<title>单笔查询接口</title>
</head>
<body style="text-align:left;">


<h1>查询（单笔）</h1>
<form method=post action="" name="">
    <table cellspacing="18" cellpadding="0" border="0" class="center_table">
        <tr>
            <td>版本（version） <span class="">*</span> </td>
            <td><input type="text" name="version" value="1.0" /></td>
        </tr>

        <tr>
            <td>外部跟踪号externalRefNumber <span class="">*</span> </td>
            <td><input type="text" name="externalRefNumber"  value="20160614142847"  /></td>
        </tr>
        <tr>
            <td>系统参考号refNumber <span class="">*</span> </td>
            <td><input type="text" name="refNumber" value="000013267981" /></td>
        </tr>
        <tr>
            <td>交易类型txnType <span class="">*</span> </td>
            <td><input type="text" name="txnType" value="VTX" /></td>
        </tr>
        <tr>
            <td>商户编号merchantId <span class="">*</span></td>
            <td><input type="text" name="merchantId" value="812330945110001" /></td>
        </tr>
        <tr>
            <td>终端编号terminalId <span class="">*</span></td>
            <td><input type="text" name="terminalId" value="33090301" /></td>
        </tr>
        <tr>
            <td>交易状态 txnStatus (S : 成功 F : 失败)<span class=""></span></td>
            <td><input type="text" name="txnStatus" value="" /></td>
        </tr>
        <tr>
            <td> </td>
            <td><input type="submit" name="submit" value="查询（单笔)"  style="padding:10px 35px;font-weight:bold;font-family:arail"></td>
        </tr>
    </table>
</form>
<?PHP

if($_POST[submit]){

function kq_ck_null($kq_va,$kq_na){if($kq_va == ""){$kq_va="";}else{return '<'.$kq_na.'>'.$kq_va.'</'.$kq_na.'>';}}

$txnStatus=kq_ck_null($_POST[txnStatus],'txnStatus');

$reqXml = '<?xml version="1.0" encoding="UTF-8"?><MasMessage xmlns="http://www.99bill.com/mas_cnp_merchant_interface"><version>'.$_POST[version].'</version><QryTxnMsgContent><externalRefNumber>'.$_POST[externalRefNumber].'</externalRefNumber><refNumber>'.$_POST[refNumber].'</refNumber><txnType>'.$_POST[txnType].'</txnType><merchantId>'.$_POST[merchantId].'</merchantId><terminalId>'.$_POST[terminalId].'</terminalId>'.$txnStatus.'</QryTxnMsgContent></MasMessage>';

    $clientcert    ="/home/flightsharecar/user_upload/php_demo/cert.pem";
    $clientprikey="/home/flightsharecar/user_upload/php_demo/private.pem";

    $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
//$challenge      = "vpos123";
    $tuCurl = curl_init();
    $merchantId='812330945110001';//商户编号
    $certPassword='vpos123';//证书密码
    $loginKey='vpos123';//商户登录密码
    $loginInfo = array(
        "Authorization: Basic " . base64_encode($merchantId . ":" . $loginKey)
    );
    curl_setopt($tuCurl, CURLOPT_URL, "https://sandbox.99bill.com:9445/cnp/query_txn");
// Set your login and password for authentication
    /*
curl_setopt($tuCurl, CURLOPT_USERPWD, 'vpos123');
curl_setopt($tuCurl, CURLOPT_POST, 1);
curl_setopt($tuCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($tuCurl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($tuCurl, CURLOPT_HTTPHEADER, $loginInfo);
curl_setopt($tuCurl, CURLOPT_SSLCERT, $clientcert);
curl_setopt($tuCurl, CURLOPT_SSLCERTPASSWD, $challenge);
curl_setopt($tuCurl, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $reqXml);
curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1);
    */
    curl_setopt($tuCurl, CURLOPT_HTTPHEADER, $loginInfo);//请求头中包含merchantId和对应的密码的内容
    //curl_setopt($tuCurl, CURLOPT_USERPWD, $loginKey);//登录用户密码

    curl_setopt($tuCurl,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($tuCurl,CURLOPT_SSL_VERIFYHOST,false);


    curl_setopt($tuCurl,CURLOPT_SSLCERTTYPE,'PEM');//证书格式
    curl_setopt($tuCurl,CURLOPT_SSLCERT,$clientcert);//证书路径
    curl_setopt($tuCurl,CURLOPT_SSLCERTPASSWD,$certPassword);//证书密码

    curl_setopt($tuCurl,CURLOPT_SSLKEYTYPE,'PEM');//本地私钥格式
    curl_setopt($tuCurl,CURLOPT_SSLKEY,$clientprikey);//私钥文件路径

    curl_setopt($tuCurl, CURLOPT_POST, 1);//POST
    curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $reqXml);//POST内容中包含报文


    curl_setopt($tuCurl,CURLOPT_TIMEOUT,30);

    curl_setopt($tuCurl,CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($ch,CURLOPT_URL,$url);

    curl_setopt($tuCurl, CURLOPT_USERAGENT,$user_agent);

    $tuData=curl_exec($tuCurl);


var_dump($tuData);

	
	echo "<html><body>结果：<br/>";//数据结果

	echo "<textarea rows=\"20\" cols=\"100\">".$reqXml."</textarea></br>";
	echo "<textarea rows=\"20\" cols=\"100\">".$tuData."</textarea></br>";


     echo "</body></html>";
    
	if (curl_error($tuCurl))
    printf("Error %s: %s", curl_errno($tuCurl), curl_error($tuCurl));
    curl_close ($tuCurl);



}
?>


</body>
</html>